#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
    pid_t id=fork();
    if(id==0)
    {
        //子进程
        int cnt=5;
        while(cnt)
        {
            printf("我是子进程：%d, 父进程：%d, cnt：%d\n",getpid(),getppid(),cnt--);
            sleep(1);
        }
        exit(10);    //正常终止
    }
    int status=0;
    //进程等待，获取子进程退出信息
    pid_t ret=waitpid(id, &status, 0);
    if(id>0)
    {
        printf("等待成功：%d, signal：%d, child exit code: %d\n",ret, (status & 0x7f), (status>>8) & 0xff);
    }
    sleep(5);
    return 0;
}
